<template>
  <div class="my-header w">
    <!-- 上面区域 -->
    <div class="header-top">
      <!-- logo -->
      <h1 class="logo">
        <router-link to="/"></router-link>
      </h1>
      <!-- 搜索-->
      <div class="center">
        <div class="center-search">
          <input type="text" name id :placeholder="zahuo" v-model="srk" @focus="jujiao(srk)" @blur="shijiao"
            @input="oninput(srk)" />
          <button class="search-btn" @click="sousuo(srk)">搜索</button>
          <div class="qqqq">
            <!-- 搜索历史 -->
            <History v-if="isInputShow"></History>
            <!-- 联想建议 -->
            <Suggestion v-else-if="inqwe"></Suggestion>
          </div>
        </div>

        <!-- 搜索下面的导航 -->
        <ul class="center-navs">
          <li>
<<<<<<< HEAD
            <a href="#/Food">美食</a>
=======
            <a href="#" @click="dianji('美食')">美食</a>
>>>>>>> 215f03e587d8f17161ec20bf613a5cff5f45ed02
          </li>
          <li>
            <a href="#" @click="dianji('餐厨')">餐厨</a>
          </li>
          <li>
            <a href="#" @click="dianji('艺术')">艺术</a>
          </li>
          <li>
            <a href="#" @click="dianji('电器')">电器</a>
          </li>
          <li>
            <a href="#" @click="dianji('居家')">居家</a>
          </li>
          <li>
            <a href="#" @click="dianji('洗护')">洗护</a>
          </li>
          <li>
            <a href="#/Baby" @click="dianji('孕婴')">孕婴</a>
          </li>
          <li>
            <a href="#/shoes" @click="dianji('服装')">服装</a>
          </li>
          <li>
            <a href="#/zahuo" @click="dianji('杂货')">杂货</a>
          </li>
        </ul>
      </div>
      <!-- 购物车 -->
      <div class="cart">
        <a href="#/cart">
          <i class="iconfont icon-cart"></i>
          购物车
<<<<<<< HEAD
          <em>{{ $store.state.count }}</em>
=======
          <em>{{ $store.state.gouwuche.qwe }}</em>
>>>>>>> 215f03e587d8f17161ec20bf613a5cff5f45ed02
        </a>
      </div>
    </div>
    <!-- 二级导航 -->
    <AppHeaderNav />


  </div>
</template>

<script>

import History from "./search/History.vue";
import Suggestion from "./search/Suggestion.vue";
import AppHeaderNav from "./AppHeaderNav.vue";
import { useStore } from "vuex";
import { ref, provide, computed, } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
import {getItem} from '@/utils/auth'
export default {
  components: {
    AppHeaderNav,
    History,
    Suggestion,
  },
  props: {
    show: {
      type: Boolean
    },
    fromCount: {
      type: Number
    }
  },
  setup(props) {
    const store = useStore();
    let isInputShow = ref(false);
    let inqwe = ref(false);
    let srk = ref("");
    let list = ref([]);

    // 触发action

    const router = useRouter()
    store.dispatch("category/getAllCategory");
    // 使用provide配置项注入数据 key - value
    provide("list", list);
    function sousuo(srk) {
      // isInputShow.value = false
      isInputShow.value = false;
      axios.get(`http://localhost:3000/data?name=${srk}`).then((res) => {
        list.value = res.data;
        // console.log(res.data);
        // localStorage.setitem('key',JSON.stringify(res.data))
        localStorage.setItem("key", JSON.stringify(res.data))
      });
    }
    function jujiao(srk) {
      if (srk.length > 0) {
        isInputShow.value = false;
        inqwe.value = true;
      } else {
        isInputShow.value = true;
      }
      // console.log(srk.length);
    }
    function shijiao() {
      isInputShow.value = false;
      inqwe.value = false;
    }
    // 监听输入框
    function oninput(srk) {
      if (srk.length > 0) {
        isInputShow.value = false;
        inqwe.value = true;
        axios.get(`http://localhost:3000/data?name=${srk}`).then((res) => {
        // list = res.data;
        // localStorage.setitem('key',JSON.stringify(res.data))
        localStorage.setItem("key",JSON.stringify(res.data))
      });
      } else {
        isInputShow.value = true;
      }
    }
    function dianji(v) {
      srk.value = v;
    }
<<<<<<< HEAD
    console.log(props.fromCount);
    
    props.fromCount = getItem('payCount')
=======

>>>>>>> 2deb3c18cf296e1f54427e5a556197793ffc65f3
    // 使用provide配置项注入数据 key - value
    // provide('zahuo', zahuo)
    return {
      sousuo,
      srk,
      isInputShow,
      jujiao,
      shijiao,
      oninput,
      inqwe,
      dianji,
      list,
<<<<<<< HEAD
      To,
      props
=======
>>>>>>> 2deb3c18cf296e1f54427e5a556197793ffc65f3
    };
  },
};
</script>

<style lang="less" scoped>
.qqqq {
  opacity: 1;
  position: absolute;
  z-index: 5;
  background-color: #fff;
  border: 1px solid #e8e8e8;
  font-size: 14px;
  // outline: 0;
  // opacity: 0;
  // top: 37px;
  left: 15px;
  // width: 423px;
}

.my-header {
  height: 120px;
  padding: 25px 0 0 0;
  background-color: #fff;

  .header-top {
    display: flex;

    .logo {
      width: 330px;
      height: 60px;

      a {
        display: inline-block;
        height: 60px;
        width: 100%;
        background: url("../assets/images/logo.webp") no-repeat 0 -298px;
      }
    }

    .center {
      flex: 1;

      .center-search {
        position: relative;
        width: 540px;
        height: 35px;

        input {
          width: 440px;
          height: 35px;
          border: 1px solid @xtxColor;
          border-radius: 20px 0 0 20px;
          padding-left: 15px;
          box-sizing: border-box;
        }

        .search-btn {
          float: right;
          width: 100px;
          height: 35px;
          color: #fff;
          background-color: @xtxColor;
          border-radius: 0 20px 20px 0;
          border: 0;
          font-size: 16px;
          cursor: pointer;
        }
      }

      .center-navs {
        width: 540px;

        li {
          float: left;
          height: 32px;
          padding: 5px;

          a {
            padding: 0 5px;
            border-right: 1px solid #ccc;

            &:hover {
              color: @xtxColor;
            }
          }
        }

        li:last-child a {
          border-right: 0;
        }
      }
    }

    .cart {
      box-sizing: border-box;
      width: 150px;
      height: 35px;
      line-height: 32px;
      border-radius: 20px;
      border: 1px solid @xtxColor;
      font-size: 15px;
      text-align: center;

      &:hover {
        background-color: #f5f3ef;
      }

      a {
        color: @xtxColor;
      }

      i {
        // font-size: 16px;
        color: @xtxColor;
      }

      em {
        color: #fff;
        background-color: red;
        border-radius: 50%;
        padding: 5px;
        display: inline-block;
        width: 11px;
        height: 9px;
        line-height: 10px;
        font-size: 10px;
        // padding: 2px 5px;
      }
    }
  }
}
</style>